<?php
namespace app\api\controller\v1;

use app\api\validate\Count;
use app\api\controller\Base;
use app\api\model\Product as ProductModel;
use app\lib\exception\MissEx;
use app\api\validate\IdMPot;
/** 
* Document
*/
class Product extends Base {
    

    public function getRecent($count = 15){
        (new Count())->goCheck();

        $res = ProductModel::getRecent($count);
        if(empty($res)) throw new MissEx('请求的商品列表不存在',30003);
        
        return $this->data($res);

    }
    
    public function getAllInCategory($id){
        (new IdMPot())->goCheck();
        $products = ProductModel::getAllInCategory($id);
        if(empty($products)) throw new MissEx('请求的商品列表不存在',30003);
        
        return $this->data($products);
    }

    public function getDetail($id){
        (new IdMPot())->goCheck();
        $res = ProductModel::getDetail($id);
        if(empty($res)) throw new MissEx('请求的商品不存在',30005);

        return $this->data($res);
    }


    
}